package exception;

/**
 * java异常处理机制中的try-catch
 */
public class TryCatchDemo {
    public static void main(String[] args) {
        System.out.println("程序开始了");
        try {
            String line = null;
//            String line = "abc";
            System.out.println(line.length());
            System.out.println(line.charAt(0));
            System.out.println(Integer.parseInt(line));
            //try语句块中出错代码以下的内容都不会被执行！！
            System.out.println("!!!!!!!!!!!!!!!!!!!!!");
        }catch(NullPointerException|StringIndexOutOfBoundsException e){
            System.out.println("出现空指针或下标越界后相同的处理方式!");
        }catch(Exception e){
            System.out.println("没出现上面异常才会出现这个异常");
        }
        System.out.println("程序结束了");
    }
}






